using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Tester.GuiActions.Actions;

namespace Tester.Forms.GuiActions.Actions
{
    public class AcceleratorUpdateVisitor : IMainMenuVisitor
    {
        public void Visit(MainMenuManager.MainMenuItem value)
        {
            MainMenuManager.MainMenuMenuItem item = value as MainMenuManager.MainMenuMenuItem;
            if (item!=null && value.Action !=null)
            {
                Accelerator accelerator = Tester.GuiActions.Actions.Actions.Instance.AcceleratorManager.Accelerators.AcceleratorByName(value.Action.Name);
                if (accelerator != null)
                {
                    try
                    {
                        item.MenuItem.ShortcutKeys =
                            (accelerator.Alt ? Keys.Alt : Keys.None) |
                            (accelerator.Ctrl ? Keys.Control : Keys.None) |
                            (accelerator.Shift ? Keys.Shift : Keys.None) |
                            accelerator.Key;
                    } catch (Exception e)
                    {
                        
                    }
                } else
                {
                    item.MenuItem.Text = item.Display; 
                }
            }
            value.Accept(this);
        }
    }
}
